package com.example.wanandroid.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.wanandroid.R;
import com.example.wanandroid.core.bean.BaseData;
import com.example.wanandroid.core.bean.main.collect.FeedArticleData;

import java.util.Objects;

/**
 * @author jiangyi
 */
public class ArticleItem extends LinearLayout {
    TextView isNewText;
    TextView authorText;
    TextView timeText;
    TextView titleText;
    TextView categoryText;
    TextView categoryHint;

    public ArticleItem(Context context) {
        super(context);
    }

    public ArticleItem(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ArticleItem(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public ArticleItem(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        isNewText = findViewById(R.id.new_article_text);
        authorText = findViewById(R.id.author_text);
        timeText = findViewById(R.id.time_text);
        titleText = findViewById(R.id.title_text);
        categoryText = findViewById(R.id.category_text);
        categoryHint = findViewById(R.id.category_hint);
    }

    public void bindData(FeedArticleData data) {
        String author = data.getAuthor();
        if(Objects.equals(author, "")) {
            author = "在线博客";
        }
        authorText.setText(author);
        timeText.setText(data.getNiceDate());
        String title = data.getTitle();
        titleText.setText(title.replace("&amp;","&"));
        categoryText.setText(data.getSuperChapterName());
        if(data.getSuperChapterName().equals("")){
            categoryHint.setText("");
        }
    }
}
